var e = require("../../@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", { value: !0 }),
  (exports.default = void 0);
var t = require("../../@babel/runtime/helpers/classCallCheck"),
  r = require("../../@babel/runtime/helpers/createClass"),
  a = require("../../@babel/runtime/helpers/inherits"),
  i = require("../../@babel/runtime/helpers/createSuper"),
  c = (function (e) {
    a(n, e);
    var c = i(n);
    function n() {
      var e;
      return (
        t(this, n),
        ((e = c.call(this)).started = !1),
        (e._gravity = { x: 0, y: 0, z: 0 }),
        (e.onAccelerometerChangeHandler = function (t) {
          var r = { x: 9.8 * t.x, y: 9.8 * t.y, z: 9.8 * t.z };
          (e._gravity.x = 0.9 * e._gravity.x + 0.1 * r.x),
            (e._gravity.y = 0.9 * e._gravity.y + 0.1 * r.y),
            (e._gravity.z = 0.9 * e._gravity.z + 0.1 * r.z);
          var a = {
              x: r.x - e._gravity.x,
              y: r.y - e._gravity.y,
              z: r.z - e._gravity.z,
            },
            i = new Date().getTime();
          e.emit("md_accWithoutGravity", { value: { acc: a, timestamp: i } }),
            e.emit("md_accWithGravity", { value: { acc: r, timestamp: i } }),
            e.emit("md_sensorAcc", {
              value: {
                timestamp: i,
                linearAcc: a,
                accelerationIncludingGravity: r,
                gravity: e._gravity,
              },
            });
        }),
        e
      );
    }
    return (
      r(n, [
        {
          key: "start",
          value: function () {
            var e = this;
            this.started ||
              ((this.started = !0),
              wx.startAccelerometer({
                interval: "game",
                success: function (e) {},
                fail: function (e) {},
                complete: function (t) {
                  e.started || e.stop();
                },
              }),
              wx.onAccelerometerChange(this.onAccelerometerChangeHandler));
          },
        },
        {
          key: "stop",
          value: function () {
            (this.started = !1),
              wx.offAccelerometerChange &&
                wx.offAccelerometerChange(this.onAccelerometerChangeHandler),
              wx.stopAccelerometer({
                success: function (e) {},
                fail: function (e) {},
                complete: function (e) {},
              });
          },
        },
      ]),
      n
    );
  })(e(require("../common/EventDispatcher.js")).default);
exports.default = c;
